<template>
  <div>
    <a-modal :visible="visible" @before-open="open" @ok.stop="handleOk" @cancel="handleCancel" :align-center="false" title-align="start" width="500px" :mask-closable="false">
      <template #title> 调拨单审核 </template>
      <div>
        <a-form auto-label-width ref="formRef" size="medium" :model="form">
          <a-space direction="vertical" :size="24">
            <a-row>
              <a-col :span="24">
                <a-form-item field="pass" label="调拨单审核" :rules="rules.pass">
                  <a-radio-group v-model="form.pass">
                    <a-radio :value="true">审核通过</a-radio>
                    <a-radio :value="false">审核驳回</a-radio>
                  </a-radio-group>
                </a-form-item>
              </a-col>
              <a-col :span="24">
                <a-form-item field="remark" label="备注">
                  <a-input v-model="form.remark" placeholder="请输入"></a-input>
                </a-form-item>
              </a-col>
            </a-row>
          </a-space>
        </a-form>
      </div>
    </a-modal>
  </div>
</template>

<script lang="ts">
  import { defineComponent, ref, reactive, toRefs, computed } from 'vue'
  import { auditTransOrder } from '@/api/warehouse'
  import { Message } from '@arco-design/web-vue'
  export default defineComponent({
    props: ['id'],
    emits: ['save'],
    setup(props: any, { emit }) {
      let visible = ref(false)
      const formRef = ref()
      const data: any = reactive({
        form: {
          pass: true,
        },
        rules: {
          pass: [{ required: true, message: '请选择是否通过' }],
        },
      })

      const open = () => {
        // getUserList()
      }

      const handleOk = () => {
        formRef.value.validate(async (valid: any) => {
          console.log(props.info)

          if (!valid) {
            let res: any = {}
            let params: any = {
              id: props.id,
              pass: data.form.pass,
              remark: data.form.remark,
            }
            res = await auditTransOrder(params)
            if (res.code == 'SUCCESS') {
              data.form = {
                pass: true,
              }
              Message.success('提交成功')
              emit('save')
              visible.value = false
            }
          }
        })
      }
      const handleCancel = () => {
        data.form = {
          pass: true,
        }
        visible.value = false
      }
      return {
        ...(toRefs(data) as any),
        visible,
        formRef,
        open,
        handleOk,
        handleCancel,
      }
    },
  })
</script>

<style lang="less" scoped></style>
